<template>
    <div class="userInfocontainer">
        <div class="lefts">
            <div class="divBorder">
                <el-form :model="form" label-width="100px">
                    <el-form-item label="用户昵称">
                        <el-input v-model="form.nickname" placeholder="请输入用户昵称" />
                    </el-form-item>
                    <!-- <el-form-item label="角色">
                        <el-select v-model="form.roleIds" multiple placeholder="请选择" disabled>
                            <el-option v-for="item in roleOptions" :key="item.roleId" :label="item.roleName"
                                :value="item.roleId" :disabled="item.status == 1"></el-option>
                        </el-select>
                    </el-form-item> -->
                    <el-form-item label="手机号码">
                        <el-input v-model="form.mobile" placeholder="请输入手机号码" />
                    </el-form-item>
                    <el-form-item label="邮箱" prop="email">
                        <el-input v-model="form.email" placeholder="请输入邮箱" />
                    </el-form-item>
                    <el-form-item label="用户账号">
                        <el-input v-model="form.username" placeholder="请输入用户账号" readonly />
                    </el-form-item>
                    <el-form-item label="用户性别">
                        <el-select v-model="form.sex" placeholder="请选择">
                            <el-option v-for="dict in sys_user_sex" :key="dict.value" :label="dict.label"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态">
                        <el-radio-group v-model="form.status" disabled>
                            <el-radio v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.value">{{
                    dict.label }}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="姓名">
                        <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
                    </el-form-item>
                    <el-form-item label="备注">
                        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                    </el-form-item>
                </el-form>
                <div class="buttonDiv">
                    <el-button type="primary" @click="onDialogFormConfirm">提交</el-button>
                </div>
            </div>
        </div>
        <div class="rights">
            <div class="divBorder">
                <el-form :model="form1" label-width="100px">
                    <el-form-item label="新密码">
                        <el-input v-model="form1.password" placeholder="请输入用户密码" type="password" show-password />
                    </el-form-item>
                    <el-form-item label="确认密码">
                        <el-input v-model="form1.passwordConfirm" placeholder="请输入用户密码" type="password" show-password />
                    </el-form-item>
                </el-form>
                <div class="buttonDiv">
                    <el-button type="primary" @click="onDialogFormConfirmPass">修改</el-button>
                </div>
            </div>

        </div>
    </div>

</template>
<script setup lang="ts">
import { ref } from 'vue'
import { selectListRoleService } from '@/api/sys/role'

const roleOptions = ref()
const sys_user_sex = [
    {
        label: "男",
        value: 0
    },
    {
        label: "女",
        value: 1
    }
]
// 状态 0：可用， 1: 不可用
const sys_normal_disable = [
    {
        label: "可用",
        value: 0
    },
    {
        label: "不可用",
        value: 1
    }
]
const form = ref({})

// 查询角色列表
const searchRole = async () => {
    try {
        let result = await selectListRoleService()
        roleOptions.value = result.data;
    } catch (e) { }
}
searchRole()

import { currentUserService, updateUserService, restPassService } from '@/api/sys/user'
import { ElMessage } from "element-plus"
// 获取登录用户信息
const getUser = async () => {
    try {
        let result = await currentUserService();
        form.value = result.data;
    } catch (e) { }
}
getUser()

// 修改个人信息
const onDialogFormConfirm = async () => {
    //修改
    try {   // 修改成功
        let result = await updateUserService(form.value)
        ElMessage.success(result.msg ? result.msg : '修改成功')
        if (result.code == 0) {
            getUser()
        }
    } catch (error) { }
}

// 修改密码
const form1 = ref({})

const onDialogFormConfirmPass = async () => {
    if (form1.value.password == form1.value.passwordConfirm) {    // 校验成功
        let param = {
            id: form.value.id,
            password: form1.value.password
        }
        const result = await restPassService(param)
        if (result.code == 0) {
            ElMessage.success(result.message ? result.message : '重置成功')
        } else {
            ElMessage.error(result.message ? result.message : '重置失败')
        }
    } else {
        ElMessage.error('密码不一致')
    }
}



</script>

<style lang="scss">
.userInfocontainer {
    display: flex;
    justify-content: center;
    flex-direction: row;
    justify-items: spance-between;
    width: 100%;

    .lefts {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        width: 60%;

        .buttonDiv {
            display: flex;
            flex-direction: row;
            justify-content: right;
            align-items: center;
        }
    }

    .rights {
        display: flex;
        flex-direction: column;
        width: 30%;

        .buttonDiv {
            display: flex;
            flex-direction: row;
            justify-content: right;
            align-items: center;
        }
    }

    .divBorder {
        width: 90%;
        padding: 20px;
        /* 设置边框 */
        border: 2px solid #add8e6;
        /* 浅蓝色边框，颜色可以根据需要调整 */

        /* 设置圆角 */
        border-radius: 10px;
        /* 圆角大小可以根据需要调整 */

        /* 设置阴影 */
        box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
        /* 阴影水平偏移、垂直偏移、模糊半径、颜色 */
    }

}
</style>